<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        //工厂模式创建对象'
        /* function createPerson(name, age) {
            var obj = new Object();
            obj.name = name;
            obj.age = age;
            obj.selfIntroduction = function () {
                console.log('我叫'+ obj.name + ',今年' + obj.age );
            };
            return obj;
        }

        var xiaoHong = createPerson('小红',18);
        xiaoHong.selfIntroduction(); */

        //自定义构造函数
        /* 
        1. 在内存中开辟(申请一块空闲的空间)空间，存储创建新的对象
        2. 把this设置为当前对象
        3. 设置对象的属性和方法
        4. 把this这个对象返回
        */
        /* function Person(name, age) {
            this.name = name;
            this.age = age;
            this.selfIntroduction = function () {
                console.log('My name is ' + this.name + ', im ' + this.age + ' years old');
            };
        }
        var xiaoHong = new Person('小红',18);
        xiaoHong.selfIntroduction(); */

        /* function Photograph(width, height, size) {
            this.width = width;
            this.height = height;
            this.size = size;
            this.show = function () {
                console.log('this is my show time! '+ this.width + ', ' + this.height + ', ' + this.size);
            };
        }
        var ph = new Photograph(12,12,12);
        ph.show(); */

        //字面量方式创建对象
        /* var obj = {
            name: '小明',
            age: 20,
            sayHi: function () {
                console.log('hi ' + this.name + ', ' + this.age);
            }
        };
        obj.eat = '吃';
        obj.sayHi();
        console.log(obj.eat); */
        
        //json格式数据
        /* var json = {
            'name': '小明',
            'age': '10',
            'sex': '男'
        };
        for (const key in json) {
            if (json.hasOwnProperty(key)) {
                console.log(json[key]);
            }
        } */

        

    </script>
</body>
</html>